package com.chm.fw.base;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import io.reactivex.disposables.Disposable;

public abstract class BaseActivity extends AppCompatActivity {

    /*
    //防止重复点击
    if (isClick) {
        return;
    }
    isClick = true;
     */
    public boolean isClick = false;

    //网络请求取消订阅
    public Disposable disposable;

    public void unSubscribe() {
        if (disposable != null && !disposable.isDisposed()) {
            disposable.dispose();
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    //onStop -> onRestart -> onStart
    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        unSubscribe();
        super.onDestroy();
    }

    public void toastGo(View view, String msg, int length) {
        Snackbar.make(view, msg, length == 0 ? Snackbar.LENGTH_SHORT : Snackbar.LENGTH_LONG)
                .setActionTextColor(Color.GREEN)
                .show();
    }
}
